package zjc.bookkeeping.minepage.aAssetaccount;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import java.util.List;
import java.util.Map;

import zjc.bookkeeping.R;

public class accountListAdapter extends BaseAdapter {

    private List<Map<String,Object>> data; //这就是数据啦
    private Context context;                //这个是上下文啦
    private LayoutInflater layoutInflater;  //用来加载布局的

    public accountListAdapter(Context context,List<Map<String,Object>> data){
        this.context=context;
        this.data=data;
        this.layoutInflater=LayoutInflater.from(context);

    }

    //就是看看一共多少项目
    @Override
    public int getCount() {
        return data.size();
    }
    //获得某一个位置的具体内容
    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    //获取唯一标识
    @Override
    public long getItemId(int position) {
        return position;
    }

    //组件的类
    public final class Widget{
        public ImageView img;
        public TextView title;
        public TextView accouunt;
        public TextView card;
        public TextView remark;
    }


    //这个就是重点啦，把数据和view合在一起
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Widget widget=null;
        //就是，那个listview有个缓存机制，会把以前有的东西缓存在convertView里
        if(convertView == null){
            widget=new Widget();
            convertView= layoutInflater.inflate(R.layout.activity_assetaccount_body_listitem,null);
            widget.img= (ImageView) convertView.findViewById(R.id.as_listitem_image);
            widget.title= (TextView) convertView.findViewById(R.id.as_listitem_title);
            widget.accouunt=(TextView)convertView.findViewById(R.id.as_listitem_account);
            widget.card=(TextView)convertView.findViewById(R.id.as_listitem_card);
            widget.remark=(TextView)convertView.findViewById(R.id.as_listitem_remark);
            //将组件与convertView联系起来
            convertView.setTag(widget);
        }else{
            widget=(Widget)convertView.getTag();
        }

        widget.img.setImageResource((Integer)data.get(position).get("image"));
        widget.title.setText((String)data.get(position).get("title"));
        widget.accouunt.setText((String)data.get(position).get("account"));
        widget.card.setText((String)data.get(position).get("card"));
        widget.remark.setText((String)data.get(position).get("remark"));

        return convertView;
    }

}
